<?php include (dirname(__FILE__)."/../include/header.php"); ?>
 <?php 
 $id=$_REQUEST['id'];
 	if(isset($_POST['submit'])){
 		$sql5="UPDATE zy_user a SET  integral = integral - (SELECT integral FROM zy_gift WHERE gift_id=".$_GET['id'].") WHERE user_id =".$_SESSION['_user']['user_id'];
		//echo $sql5;
		mysql_query($sql5);
		$sql6="insert into zy_gift_delivery(gift_id,user_id,Conversiontime,address,phone,name) values ('$_GET[id]',".$_SESSION['_user']['user_id'].",now(),'$_POST[address]','$_POST[phone]','$_POST[name]')";
	//	echo $sql6;
		 mysql_query($sql6);
		header("location:".SITE_ROOT."/gift");
	}
?>
<?php 
$sql7="select * from zy_address where is_delete=0 and user_id=".$_SESSION['_user']['user_id'];
$result=mysql_query($sql7);
$rs7=mysql_fetch_array($result);
$sql8="select * from zy_user where user_id =".$_SESSION['_user']['user_id'];
// echo $sql8;
$result2=mysql_query($sql8);
$rs8=mysql_fetch_array($result2);
?>
<!DOCTYPE html>
<html lang="zh">
<head>
<title>点一下,宁波最大的外卖订餐网站!</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="外卖,网上订餐,餐厅,美食" />
<meta name="description" content="查看附近的餐厅、美食信息" />
<meta http-equiv="X-UA-Compatible" content="chrome=IE6">
<script type="text/javascript" src="<?php echo SITE_ROOT;?>/js/jquery-1.8.0.js"></script>
<script type="text/javascript" src="<?php echo SITE_ROOT;?>/js/bootstrap/js/bootstrap.min.js"></script>
 <Script type="text/javascript">
function examine(){
	var q = document.getElementById("name").value;
	 var s =document.getElementById("address").value;
  var t =document.getElementById("phone").value;
  var w=document.getElementById("giftname").value;
  var x=document.getElementById("integral").value;
  var str="收获人姓名:"+q+"\n"+"地址:"+s+"\n"+ "电话:"+t+"\n"+"你要兑换的礼品为:"+w+"\n"+"消耗的积分为:"+x+"\n";
  if(s=="" || t=="" || q==""){
	  alert("收货人,地址,电话不能为空,请如实填写");
	  return false;
	  }
	if(s!=""&&t!=""&&q!=""){
  if(confirm(str)){
		return true;
	}else{
		return false;
}
	}
}
</Script>
</head>
<body>
<?php 
$sql="select * from zy_gift where gift_id =".$id;
$result=mysql_query($sql);
$zy_gift=mysql_fetch_array($result);
?>
<div class="full-content-wrapper">
  <div class="cart-container">
    <div class="row cart-wrapper">
      <div class="span9 main-box bordered-box">
        <h2>确认您的收货地址</h2>
        <div class="row">
          <div class="span4 address-form">
            <form action="" name="form1" method="post" id="checkout-form" class="form-horizontal" onSubmit="return examine();">
              <fieldset>
			    <div class="address-row control-group">
                  <label class="control-label" for="name"><span class="required-mark">*</span>收货人：</label>
                  <div class="controls">
                    <input class="span3" id="name" name="name" size="30" type="text" value="<?php echo $rs8['username']?>" />
                    <p class="help-block">(请如实填写您的姓名)</p>
                  </div>
                </div>
                <div class="address-row control-group">
                  <label class="control-label" for="address"><span class="required-mark">*</span>详细地址：</label>
                  <div class="controls">
                    <input class="span3" id="address" name="address" size="30" type="text" value="<?php echo $rs7['address']?>" />
                    <p class="help-block">(请填详细一点)</p>
                  </div>
                </div>
                <div class="phone-row control-group">
                  <label for="phone" class="control-label"><span class="required-mark">*</span>联系电话：</label>
                  <div class="controls">
                    <input class="span3" id="phone" name="phone" size="30" type="text" value="<?php echo $rs7['phone']?>"/>
                    <span class="help-block">(请如实填写您的电话以便我们联系您)</span> </div>
                </div>
                <!-- /control-group -->
                <div class="phone-bk-row control-group">
                  
                  <div class="controls">
                    <input type="hidden" name="giftname" id="giftname" value="<?php echo $zy_gift['gift_name']; ?>"/>
					<input type="hidden" name="integral" id="integral" value="<?php echo $zy_gift['integral']; ?>"/>
                     </div>
                </div>
				
          <div class="confirm-button-wrapper" id="normal_payment_button" style="float:right; margin-right:25px;" >
			  <input type="submit" name="submit" id="submit" value="提交" class="btn btn-yellow" >
          </div>
       
              </fieldset>
            </form>
          </div>
		  <div class="span5 address-list">
            <ul class="checkout-address-list" id="checkout-address-list">
             <?php if(isset($_SESSION['_user'])){
	             	$res=mysql_query("select * from zy_address where is_delete=0 and user_id=".$_SESSION['_user']['user_id']);
	             	while($result=mysql_fetch_array($res)){
	             	?>
              <li class="<?php if($result['is_default']==1){echo "current";}?>">
                <input type="radio" class="radio" name="address[id]" <?php if($result['is_default']==1){echo "checked=\"checked\"";}?> value="<?php echo $result['add_id']?>" />
                <span class="address"><?php echo $result['address'];?></span> <br/>
                <span class="phone"><?php echo $result['phone'];?></span> <span class="tel"><?php echo $result['tel'];?></span></li>
              <li>
            <?php }?>
                <input type="radio" class="radio" name="address[id]" value="new" id="address-new"/>
                <span class="use-new">使用新地址</span> <span class="address hidden"></span> <span class="phone hidden"></span> <span class="phone-bk hidden"></span> </li>
           <?php }?>
            </ul>
			</div>
       
      </div>
    </div>
  </div>
 <?php include (dirname(__FILE__)."/../include/footer.php"); ?>
